home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gimp.idb / usr / freeware / share / gimp / scripts / line-nova.scm.z / line-nova.scm
Encoding:
GIMP Script-Fu Script  |  1999-07-21  |  3.6 KB  |  97 lines

  1. ;;; line-nova.scm -*-scheme-*-
  2. ;;; Time-stamp: <1998/01/17 21:15:38 narazaki@InetQ.or.jp>
  3. ;;; Author Shuji Narazaki <narazaki@inetq.or.jp>
  4. ;;; Version 0.6
  5.  
  6. (if (not (symbol-bound? 'script-fu-line-nova-num-of-lines (the-environment)))
  7.     (define script-fu-line-nova-num-of-lines 200))
  8. (if (not (symbol-bound? 'script-fu-line-nova-corn-deg (the-environment)))
  9.     (define script-fu-line-nova-corn-deg 1.0))
  10. (if (not (symbol-bound? 'script-fu-line-nova-offset (the-environment)))
  11.     (define script-fu-line-nova-offset 100))
  12. (if (not (symbol-bound? 'script-fu-line-nova-variation (the-environment)))
  13.     (define script-fu-line-nova-variation 30))
  14.  
  15. (define (script-fu-line-nova img drw num-of-lines corn-deg offset variation)
  16.   (let* ((*points* (cons-array (* 3 2) 'double))
  17.      (modulo fmod)            ; in R4RS way
  18.      (pi/2 (/ *pi* 2))
  19.      (pi/4 (/ *pi* 4))
  20.      (pi3/4 (* 3 pi/4))
  21.      (pi5/4 (* 5 pi/4))
  22.      (pi3/2 (* 3 pi/2))
  23.      (pi7/4 (* 7 pi/4))
  24.      (2pi (* 2 *pi*))
  25.      (rad/deg (/ 2pi 360))
  26.      (variation/2 (/ variation 2))
  27.      (drw-width (car (gimp-drawable-width drw)))
  28.      (drw-height (car (gimp-drawable-height drw)))
  29.      (drw-offsets (gimp-drawable-offsets drw))
  30.      (old-selection (car (gimp-selection-save img)))
  31.      (radius (max drw-height drw-width))
  32.      (index 0)
  33.      (dir-deg/line (/ 360 num-of-lines)))
  34.     (define (draw-vector beg-x beg-y direction)
  35.       (define (set-point! index x y)
  36.     (aset *points* (* 2 index) x)
  37.     (aset *points* (+ (* 2 index) 1) y))
  38.       (define (deg->rad rad)
  39.     (* (modulo rad 360) rad/deg))
  40.       (define (set-marginal-point beg-x beg-y direction)
  41.     (let ((dir1 (deg->rad (+ direction corn-deg)))
  42.           (dir2 (deg->rad (- direction corn-deg))))
  43.       (define (aux dir index)
  44.         (set-point! index 
  45.             (+ beg-x (* (cos dir) radius))
  46.             (+ beg-y (* (sin dir) radius))))
  47.       (aux dir1 1)
  48.       (aux dir2 2)))
  49.       (let ((dir0 (deg->rad direction))
  50.         (of (+ offset (- (modulo (rand) variation) variation/2))))
  51.     (set-point! 0 
  52.             (+ beg-x (* of (cos dir0)))
  53.             (+ beg-y (* of (sin dir0))))
  54.     (set-marginal-point beg-x beg-y direction)
  55.     (gimp-free-select img 6 *points* ADD
  56.               TRUE        ; antialias
  57.               FALSE        ; feather
  58.               0        ; feather radius 
  59.               )))
  60.  
  61.     (gimp-undo-push-group-start img)
  62.     (gimp-selection-none img)
  63.     (srand (realtime))
  64.     (while (< index num-of-lines)
  65.       (draw-vector (+ (nth 0 drw-offsets) (/ drw-width 2))
  66.            (+ (nth 1 drw-offsets) (/ drw-height 2))
  67.            (* index dir-deg/line))
  68.       (set! index (+ index 1)))
  69.     (gimp-bucket-fill img drw FG-BUCKET-FILL NORMAL 100 0 FALSE 0 0)
  70.     (gimp-selection-load img old-selection)
  71.     ;; (gimp-image-set-active-layer img drw)
  72.     ;; delete extra channel by Sven Neumann <neumanns@uni-duesseldorf.de>
  73.     (gimp-image-remove-channel img old-selection)
  74.     (gimp-undo-push-group-end img)
  75.     (set! script-fu-line-nova-num-of-lines num-of-lines)
  76.     (set! script-fu-line-nova-corn-deg corn-deg)
  77.     (set! script-fu-line-nova-offset offset)
  78.     (set! script-fu-line-nova-variation variation)
  79.     (gimp-displays-flush)))
  80.  
  81. (script-fu-register
  82.  "script-fu-line-nova"
  83.  "<Image>/Script-Fu/Render/Line Nova"
  84.  "Line Nova. Draw lines with Foreground color from the center of image to the edges. 1st undo cancels bucket-fill. 2nd undo gets orignal selection."
  85.  "Shuji Narazaki <narazaki@InetQ.or.jp>"
  86.  "Shuji Narazaki"
  87.  "1997"
  88.  "RGB*, INDEXED*, GRAY*"
  89.  SF-IMAGE "Image to use" 0
  90.  SF-DRAWABLE "Drawable to draw line" 0
  91.  SF-VALUE "Number of lines" (number->string script-fu-line-nova-num-of-lines)
  92.  SF-VALUE "Sharpness (deg.)" (number->string script-fu-line-nova-corn-deg)
  93.  SF-VALUE "Offset radius" (number->string script-fu-line-nova-offset)
  94.  SF-VALUE "- randomness" (number->string script-fu-line-nova-variation)
  95. )
  96. ;;; line-nova.scm ends here
  97.